﻿using Gecko.Services;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web.Http;

namespace Gecko.Controllers
{
    public class LeakContentController : ApiController
    {

        // GET api/leakcontent
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/leakcontent/5
        public HttpResponseMessage Get(int id)
        {
            using (var waterLeakResourceService = new WaterLeakResourceService())
            {
                var resource = waterLeakResourceService.GetImage(id);
                if (resource != null)
                {
                    HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);

                    Stream stream = new MemoryStream(resource.Resource);
                    result.Content = new StreamContent(stream);
                    result.Content.Headers.ContentType = new MediaTypeHeaderValue(resource.MediaType);
                    return result;
                }
                return new HttpResponseMessage(HttpStatusCode.NotFound);
            }

        }

        // POST api/leakcontent
        public void Post([FromBody]string value)
        {
        }

        // PUT api/leakcontent/5
        public void Put(int id, [FromBody]string value)
        {
        }

        // DELETE api/leakcontent/5
        public void Delete(int id)
        {
        }
    }
}
